﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RobotJog.CApRJRobotJogNotificationService
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.RobotJog;

internal static class CApRJRobotJogNotificationService
{
  private static bool _isTesting = true;
  private static CApRJRobotJogNotificationService.INotificationService _notificationService;

  static CApRJRobotJogNotificationService() => CApRJRobotJogNotificationService.IsTesting = false;

  public static bool IsTesting
  {
    get => CApRJRobotJogNotificationService._isTesting;
    set
    {
      if (CApRJRobotJogNotificationService._isTesting == value)
        return;
      CApRJRobotJogNotificationService._isTesting = value;
      if (CApRJRobotJogNotificationService._isTesting)
        CApRJRobotJogNotificationService._notificationService = (CApRJRobotJogNotificationService.INotificationService) new CApRJRobotJogNotificationService.TestNotificationService();
      else
        CApRJRobotJogNotificationService._notificationService = (CApRJRobotJogNotificationService.INotificationService) new CApRJRobotJogNotificationService.DialogNotificationService();
    }
  }

  public static DialogResult Notify(
    string text,
    string caption,
    MessageBoxButtons buttons,
    MessageBoxIcon icon)
  {
    return CApRJRobotJogNotificationService._notificationService.Notify(text, caption, buttons, icon);
  }

  public static DialogResult NotifyModal(
    string text,
    string caption,
    MessageBoxButtons buttons,
    MessageBoxIcon icon)
  {
    return CApRJRobotJogNotificationService._notificationService.NotifyModal(text, caption, buttons, icon);
  }

  public static DialogResult SuppressibleNotify(
    string text,
    string caption,
    string identifier,
    MessageBoxButtons buttons,
    MessageBoxIcon icon,
    DialogResult defaultButton)
  {
    return CApRJRobotJogNotificationService._notificationService.SuppressibleNotify(text, caption, identifier, buttons, icon, defaultButton);
  }

  private interface INotificationService
  {
    DialogResult Notify(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon);

    DialogResult NotifyModal(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon);

    DialogResult SuppressibleNotify(
      string text,
      string caption,
      string identifier,
      MessageBoxButtons buttons,
      MessageBoxIcon icon,
      DialogResult defaultButton);
  }

  private class DialogNotificationService : CApRJRobotJogNotificationService.INotificationService
  {
    public DialogResult Notify(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon)
    {
      return TxMessageBox.Show(text, caption, buttons, icon);
    }

    public DialogResult NotifyModal(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon)
    {
      return TxMessageBox.ShowModal(text, caption, buttons, icon);
    }

    public DialogResult SuppressibleNotify(
      string text,
      string caption,
      string identifier,
      MessageBoxButtons buttons,
      MessageBoxIcon icon,
      DialogResult defaultButton)
    {
      return TxDoNotShowAgainMessageBox.Show(text, caption, identifier, buttons, icon, defaultButton);
    }
  }

  private class TestNotificationService : CApRJRobotJogNotificationService.INotificationService
  {
    public DialogResult Notify(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon)
    {
      return this.GetConfirmationResult(buttons);
    }

    public DialogResult NotifyModal(
      string text,
      string caption,
      MessageBoxButtons buttons,
      MessageBoxIcon icon)
    {
      return this.GetConfirmationResult(buttons);
    }

    public DialogResult SuppressibleNotify(
      string text,
      string caption,
      string identifier,
      MessageBoxButtons buttons,
      MessageBoxIcon icon,
      DialogResult defaultButton)
    {
      return defaultButton;
    }

    private DialogResult GetConfirmationResult(MessageBoxButtons buttons)
    {
      switch (buttons)
      {
        case MessageBoxButtons.OK:
        case MessageBoxButtons.OKCancel:
          return DialogResult.OK;
        case MessageBoxButtons.YesNoCancel:
        case MessageBoxButtons.YesNo:
          return DialogResult.Yes;
        default:
          return DialogResult.None;
      }
    }
  }
}
